package com.xin.di.uav.operate.mapper;

import com.xin.di.uav.common.response.IdAndNameResp;
import com.xin.di.uav.operate.po.DeliveryPointPO;
import com.xin.di.uav.operate.po.PlacementPoint;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface CustomDeliveryPointMapper {

    @Insert({"<script>",
            "insert into placement_point (id,sender_latitude,sender_longitude,scenic_spot_id ,name, latitude, longitude, status, express_fee)\n" +
                    "values (#{id},#{senderLatitude},#{senderLongitude},#{scenicSpotId}, #{name}, #{latitude}, #{longitude}, #{status}, #{expressFee})",
            "</script>"})
    int insert(DeliveryPointPO deliveryPointPO);

    @Select({"<script>",
            "select id, name,sender_longitude,sender_latitude ,scenic_spot_id, latitude, longitude, status, express_fee, create_time, update_time \n" +
                    " from placement_point where 1=1 " +
                    "    <if test='name != null and name !=\"\" '> and name like CONCAT('%', #{name}, '%')</if>",
            " order by create_time desc   limit #{offset},#{pageSize} ",
            "</script>"})
    List<DeliveryPointPO> selectList(@Param("offset") int offset, @Param("pageSize") int pageSize, @Param("name") String name);


    @Select({"<script>",
            "select count(1) \n" +
                    " from placement_point where 1=1 " +
                    "    <if test='name != null and name !=\"\" '> and name like CONCAT('%', #{name}, '%')</if>",
            "</script>"})
    int countList(@Param("name") String name);


    @Select({"<script>",
            " select id, sort, name, longitude, latitude, express_fee, status, create_time, update_time,\n" +
                    "                             processed_by, scenic_spot_id, deleted, express_duration, sender_longitude, sender_name,\n" +
                    "                             sender_latitude, sender_tel, sender_addr   from placement_point where id =#{id} ",
            "</script>"})
    PlacementPoint selectById(String id);


    @Update({
            "<script>",
            "UPDATE placement_point ",
            "<set>",
            "    <if test='name != null'>name = #{name},</if>",
            "    <if test='status != null'>status = #{status},</if>",
            "    update_time = NOW()",

            "</set>",
            "WHERE id = #{id}",
            "</script>"
    })
    int updateById(PlacementPoint placementPoint);

    @Select({"<script>",
            "select scenic_spot_id as id,name as name from placement_point where scenic_spot_id in ",
            "       <foreach item=\"id\" collection=\"ids\" open=\"(\" separator=\",\" close=\")\">\n" +
                    "            #{id}\n" +
                    "        </foreach>" +
            "</script>"})
    List<IdAndNameResp> selIdAndNameResp(List<String> ids);

}
